package com.lzb.randomturntable.dialog;

import android.content.Context;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;

import androidx.annotation.NonNull;

import com.lzb.basic.dialog.BaseSmartDialog;
import com.lzb.basic.utils.SPUtil;
import com.lzb.randomturntable.Content;
import com.lzb.randomturntable.R;
import com.lzb.randomturntable.databinding.DialogTurntableSettingBinding;


public class TurntableSettingDialog extends BaseSmartDialog<DialogTurntableSettingBinding> implements View.OnClickListener {

    private int duration;

    public TurntableSettingDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected boolean canceledOnTouchOutside() {
        return true;
    }

    @Override
    protected int getGravity() {
        return Gravity.BOTTOM;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.dialog_turntable_setting;
    }

    @Override
    protected void initView(View view) {
        mDataBinding.ivCancel.setOnClickListener(this);
        mDataBinding.ivMin.setOnClickListener(this);
        mDataBinding.ivAdd.setOnClickListener(this);

        duration = SPUtil.getInt(getContext(), Content.rotateDuration, 1);
        mDataBinding.tvDuration.setText(duration + "s");
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.ivCancel) {
            dismiss();
        } else if (id == R.id.ivMin) {//-
            if (duration != 1) {
                duration--;
                SPUtil.putInt(getContext(), Content.rotateDuration, duration);
            }
            mDataBinding.tvDuration.setText(duration + "s");
        } else if (id == R.id.ivAdd) {//+
            duration++;
            SPUtil.putInt(getContext(), Content.rotateDuration, duration);
            mDataBinding.tvDuration.setText(duration + "s");
        }
    }

    private Ilistener listener;

    public void setListener(Ilistener listener) {
        this.listener = listener;
    }

    public interface Ilistener {
        void clickDelete();
    }
}
